package com.xbz.admin.controller;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xbz.admin.service.UserService;
import com.xbz.common.entity.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xinmu123
 * @since 2022-05-09
 */
@RestController
@RequestMapping("/admin/sys-user")
@Api
public class UserController {

    @Autowired
    UserService userService;

    @ApiOperation("测试:查询全部的用户")
    @GetMapping("user-list")
    public List<User> test(){
        BaseMapper<User> baseMapper = userService.getBaseMapper();
        return baseMapper.selectList(null);
    }


    @ApiOperation("测试:添加用户")
    @GetMapping("adduser")
    public int add(User user){

        BaseMapper<User> baseMapper = userService.getBaseMapper();
        int insert = baseMapper.insert(user);
        if (insert>0){
            return insert;

        }else return 0;
    }

    @ApiOperation("测试:查询全部的用户")
    @GetMapping("user-list/{pageNum}")
    public List<User> test(@PathVariable(value = "pageNum") int pageNum){

        Page<User> page = new Page<>(pageNum,5);

        BaseMapper<User> baseMapper = userService.getBaseMapper();
        Page<User> sysUserPage = baseMapper.selectPage(page, null);
        List<User> records = sysUserPage.getRecords();
        return records;
    }


}

